/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package TreeView;

/**
 *
 * @author Mr.Sam
 */
import java.awt.*;
import java.awt.event.*;
import fr.ove.openmath.jome.model.*;
import fr.ove.openmath.jome.model.events.*;
import fr.ove.openmath.jome.ctrl.linear.*;

public class TreeView extends Frame {
    LinearParser parser;
    Formula formula;
    View display;
    TextField tf = new TextField();
    ScrollPane sp = new ScrollPane();
    
    public TreeView() {
        setLayout(new BorderLayout());
        setBounds(50, 50, 500, 300);
        
        add("Center", sp);
	    
	    parser = new LinearParser();
	    formula = new Formula();
	    parser.addLinearParserListener(formula);
	    display = new View();
        display.tick.setTickType(TreeTick.NONE);
        
        String prop = "FORMULA  --[ ";
        prop += "Strahler = " + formula.getNbStrahler();
        prop += ", Depth = " + formula.getDepth();
        prop += ", Width = " + formula.getNbChildren();
        prop += " ]";
	    display.setProperties(prop);
        
	    
	    formula.addModelListener(display);
	    
        Panel innerPanel = new Panel();
        innerPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
	    innerPanel.add(display);
	    sp.add(innerPanel);
	    
	    Panel comm = new Panel(new BorderLayout()); 
	    comm.add("Center", tf);
	    
	    Panel but = new Panel(new FlowLayout(FlowLayout.LEFT, 0, 0));
	    Button b = new Button("Show Tree Info");
	    b.addActionListener(
	        new ActionListener() {
	            public void actionPerformed(ActionEvent ae) {
                    parser.parse(tf.getText());
                    sp.validate();
	            }
	        }
	    );
	    but.add(b);
	    
	    comm.add("East", but);
	    
	    add("South", comm);
	    
    }
	
	public static void main(String args[]) {
	    TreeView f = new TreeView();
    	f.addWindowListener(
		    new WindowAdapter() {
        		public void windowClosing(WindowEvent event) {
        		    event.getWindow().dispose();
                    System.exit(0);
        		}
        	}
        );
	    
	    f.setVisible(true);
	}
}